package top.iwife.httpclient.model;

import top.iwife.httpclient.enums.HttpMethodEnum;

import java.util.List;

/**
 * Author 张杰
 * CreateTime 2021/11/17
 * <p>
 * http请求配置
 * 只支持标准的get和post的传参形式，如果post方法用url传参是传不了的，所以get是url，post是body。
 */
public class HttpRequestOption {
    /**
     * url
     * <p>
     * ex:http://ip:port/xxx/
     */
    private final String url;
    /**
     * @see HttpMethodEnum
     */
    private final HttpMethodEnum method;
    /**
     * get url params
     * <p>
     * 如果有一个字段需要数组，add多次就可以，只要保证name相同，如：
     * list.add("ids", "1");
     * list.add("ids", "2");
     * list.add("name", "tom");
     * http://ip:port/xxx?id=1&id=2&name=tom
     *
     * @see HttpRequestParam
     */
    private List<HttpRequestParam> params;
    /**
     * post json or form
     */
    private byte[] body;
    /**
     * http header
     *
     * @see HttpRequestHeader
     */
    private List<HttpRequestHeader> headers;

    public HttpRequestOption(String url, HttpMethodEnum method) {
        this.url = url;
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public HttpMethodEnum getMethod() {
        return method;
    }

    public List<HttpRequestParam> getParams() {
        return params;
    }

    public void setParams(List<HttpRequestParam> params) {
        this.params = params;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public List<HttpRequestHeader> getHeaders() {
        return headers;
    }

    public void setHeaders(List<HttpRequestHeader> headers) {
        this.headers = headers;
    }
}
